package com.zhoug.common3.utils.zip;

import java.io.File;
import java.io.IOException;

/**
 * @Author 35574
 * @Date 2021/3/18
 * @Description
 */
public class ZipUtils2 {
    private static final String TAG = ">>>ZipUtils";
    private static final boolean DEBUG = false;

    /**
     * 解压zip文件
     * @param srcFile zip文件
     * @param desFile 解压后的文件
     */
    public static void unZip(File srcFile, File desFile) throws Exception {
        /*if (srcFile == null || !srcFile.exists()) {
            throw new IllegalArgumentException("zip文件不存在");
        }
        if (desFile == null) {
            throw new IllegalArgumentException("desFile is null");
        }
        mkdirs(desFile);
        if (DEBUG) {
            LogUtils.d(TAG, "##############开始解压:" + srcFile.getAbsolutePath());
        }
        ZipArchiveInputStream zipInputStream = null;
        try {
            zipInputStream = new ZipArchiveInputStream(new BufferedInputStream(new FileInputStream(srcFile)));
            ZipArchiveEntry zipEntry = null;
            while ((zipEntry = zipInputStream.getNextZipEntry()) != null) {
                String fileName = zipEntry.getName();
                File temp = new File(desFile, fileName);
                if (DEBUG) {
                    LogUtils.d(TAG, "temp:" + temp);
                }
                //文件夹
                if (zipEntry.isDirectory()) {
                    mkdirs(temp);
                    continue;
                }
                //创建父目录
                mkdirs(temp.getParentFile());
                OutputStream os=null;
                try {
                    os= new BufferedOutputStream(new FileOutputStream(temp));
                    IOUtils.copy(zipInputStream, os, false);
                } catch (Exception e) {
                    e.printStackTrace();
                } finally {
                    IOUtils.close(os);
                }

            }
            if (DEBUG) {
                LogUtils.d(TAG, "##############解压完成###########");
            }
        } catch (IOException e) {
            e.printStackTrace();
        } finally {
            IOUtils.close(zipInputStream);
        }*/
    }


    /**
     * 创建文件夹
     *
     * @param file
     * @throws IOException
     */
    private static void mkdirs(File file) throws IOException {
        /*if (file != null && !file.exists()) {
            if (!file.mkdirs()) {
                throw new IOException("创建文件夹失败:" + file.getAbsolutePath());
            }
        }*/
    }

}
